const fs = require('fs')
const path = require('path');

// config path.
const mainSchemaPath = path.join(__dirname, '../prisma/schema.prisma');
const modeDir = path.join(__dirname, '../prisma/schemas/');
console.log("🚀 ~ modeDir:", modeDir)

// Read main file content

let mainSchema = fs.readFileSync(mainSchemaPath, 'utf8');

// Read all separate schema files
const modelFiles = fs.readdirSync(modeDir).filter(file => file.endsWith('.prisma'));
let modelsContent = ``;

modelFiles.forEach(file => {
  const content = fs.readFileSync(path.join(modeDir, file), 'utf8');
  console.log("🚀 ~ content:", content)
  modelsContent += content + '\n\n';
});

// Replace main file mark
mainSchema = mainSchema.replace('// <!-- MODELS -->', modelsContent.trim());

// Write updated main file
fs.writeFileSync(mainSchemaPath, mainSchema, 'utf8');

console.log('Models merged successfully!');